﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HT.Data.Util
{
    public static class Serialization
    {

        public static byte[] BinarySerialize(object serializableObject)
        {
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            formatter.Serialize(ms, serializableObject);
            ms.Position = 0;
            return ms.ToArray();
        }

        public static object BinaryDeSerialize(byte[] bytes)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes);
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            object obj = formatter.Deserialize(ms);
            ms.Close();

            return obj;
        }




    }
}
